package com.controller;

import com.pojo.Follows;
import com.pojo.Result;
import com.service.FollowsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/follows")
public class FollowsController {

    private final FollowsService followsService;

    @Autowired
    public FollowsController(FollowsService followsService) {
        this.followsService = followsService;
    }

    /**
     * 关注用户
     */
    @PostMapping("/{followerId}/follow/{followedId}")
    public Result<Void> followUser(
            @PathVariable Integer followerId,
            @PathVariable Integer followedId) {

        return followsService.followUser(followerId, followedId);
    }

    /**
     * 取消关注用户
     */
    @DeleteMapping("/{followerId}/unfollow/{followedId}")
    public Result<Void> unfollowUser(
            @PathVariable Integer followerId,
            @PathVariable Integer followedId) {

        return followsService.unfollowUser(followerId, followedId);
    }

    /**
     * 取消关注者的所有关注
     */
    @DeleteMapping("/follower/{followerId}/all")
    public Result<Void> unfollowAllByFollower(
            @PathVariable Integer followerId) {

        return followsService.unfollowAllByFollower(followerId);
    }

    /**
     * 取消被关注者的所有粉丝
     */
    @DeleteMapping("/followed/{followedId}/all")
    public Result<Void> unfollowAllByFollowed(
            @PathVariable Integer followedId) {

        return followsService.unfollowAllByFollowed(followedId);
    }

    /**
     * 检查是否关注
     */
    @GetMapping("/{followerId}/is-following/{followedId}")
    public Result<Boolean> isFollowing(
            @PathVariable Integer followerId,
            @PathVariable Integer followedId) {

        return followsService.isFollowing(followerId, followedId);
    }

    /**
     * 获取关注数量
     */
    @GetMapping("/{followerId}/following/count")
    public Result<Integer> getFollowingCount(
            @PathVariable Integer followerId) {

        return followsService.getFollowingCount(followerId);
    }

    /**
     * 获取粉丝数量
     */
    @GetMapping("/{followedId}/followers/count")
    public Result<Integer> getFollowersCount(
            @PathVariable Integer followedId) {

        return followsService.getFollowersCount(followedId);
    }

    /**
     * 获取关注列表
     */
    @GetMapping("/{followerId}/following")
    public Result<List<Follows>> getFollowingList(
            @PathVariable Integer followerId) {

        return followsService.getFollowingList(followerId);
    }

    /**
     * 获取粉丝列表
     */
    @GetMapping("/{followedId}/followers")
    public Result<List<Follows>> getFollowersList(
            @PathVariable Integer followedId) {

        return followsService.getFollowersList(followedId);
    }
}